/** @license
 * MIT License
 *
 * Copyright (c) 2018
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
import { View, Text, Radio, Label, RadioGroup } from '@tarojs/components'
import classnames from 'classnames'
import React from 'react'

import Header from '../../../../components/head/head'

import './index.scss'

export default class PageRadio extends React.Component {
  state = {
    isChecked: false,
    selectValue: '中国',
    list: [
      {
        value: '美国',
        text: '美国',
        checked: false
      },
      {
        value: '中国',
        text: '中国',
        checked: true
      },
      {
        value: '巴西',
        text: '巴西',
        checked: false
      },
      {
        value: '日本',
        text: '日本',
        checked: false
      },
      {
        value: '英国',
        text: '英国',
        checked: false
      },
      {
        value: '法国',
        text: '法国',
        checked: false
      }
    ]
  }

  radioChange = e => {
    this.setState({
      selectValue: e.detail.value
    })
  }

  render() {
    return (
      <View className='components-page'>
        <View className='components-page__header'>
          <Header title='Radio'></Header>
        </View>
        <View className='components-page_body'>
          <View className='example'>
            <View className='example-header-radio'>
              <Text>默认样式</Text>
            </View>
            <View className='example-radio'>
              <Label className='example-radio-label'>
                <Radio className="example-radio-label__radio" value='选中' checked groupId='group1' />
                <Text className='example-title'>选中</Text>
              </Label>

              <Label className='example-radio-label'>
                <Radio style='margin-left: 20rpx' value='未选中' groupId='group1' />
                <Text className='example-title'>未选中</Text>
              </Label>
            </View>
          </View>
          <View className='example'>
            <View className='example-header-radio'>
              <Text>推荐展示样式</Text>
            </View>
            <View className='example-radio-group'>
              <View className='example-radio__select-box'>
                <Text>选中的值是: {this.state.selectValue}</Text>
              </View>
              <View className='example-radio__radios-box'>
                <RadioGroup id='radio-group' className='radio-vertical' onChange={this.radioChange}>
                  <View className='example-radio__radios'>
                    {this.state.list.map((item, i) => {
                      return (
                        <View
                          className={ classnames('example-radio__radios-label', {
                            'example-radio__radios-label__active': i === this.state.list.length - 1
                          }) }
                          for={i} key={i}
                        >
                          <Radio id={i} value={item.value} checked={item.checked} groupId='radio-group' />
                          <Text className='example-title'>{item.text}</Text>
                        </View>
                      )
                    })}
                  </View>
                </RadioGroup>
              </View>
            </View>
          </View>
        </View>
      </View >
    )
  }
}
